/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:58 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class HinhthuckiemtraDAL : SqlProvider<HinhthuckiemtraEntity>
    {
        static HinhthuckiemtraDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                HinhthuckiemtraEntity entity = new HinhthuckiemtraEntity();
				entity.PK_iHinhthuckiemtraID = Int16.Parse("0"+dr["PK_iHinhthuckiemtraID"].ToString());
				entity.sTenhinhthuckiemtra = dr["sTenhinhthuckiemtra"].ToString();
				entity.sKyhieu = dr["sKyhieu"].ToString();
                return entity;
            };
        }
        public static HinhthuckiemtraEntity GetOne(Int16 PK_iHinhthuckiemtraID)
        {
            string cmdName = "spHinhthuckiemtra_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iHinhthuckiemtraID", PK_iHinhthuckiemtraID);
            HinhthuckiemtraEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<HinhthuckiemtraEntity> GetAll()
        {
            string cmdName = "spHinhthuckiemtra_Get";
            return GetList(cmdName);
        }
        
        public static int Add(HinhthuckiemtraEntity entity)
        {
            string cmdName = "spHinhthuckiemtra_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(HinhthuckiemtraEntity entity)
        {
            string cmdName = "spHinhthuckiemtra_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int16 PK_iHinhthuckiemtraID)
        {
            string cmdName = "spHinhthuckiemtra_Delete";
            SqlParameter p = new SqlParameter("@PK_iHinhthuckiemtraID", PK_iHinhthuckiemtraID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(HinhthuckiemtraEntity entity)
        {
            SqlParameter[] p = new SqlParameter[3];
			p[0] = new SqlParameter("@PK_iHinhthuckiemtraID", entity.PK_iHinhthuckiemtraID);
			p[1] = new SqlParameter("@sTenhinhthuckiemtra", entity.sTenhinhthuckiemtra);
			p[2] = new SqlParameter("@sKyhieu", entity.sKyhieu);
            return p;
        }
        #endregion
       
    }
}